import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SpringLayout;


@SuppressWarnings("serial")
public class ContainersGraph extends JPanel {
	
	private static JPanel cPanel;
	private static JScrollPane scrollPane;
	private static int nContainers = 50;
	
	private JPanel createContainers(int n) {
		JPanel gridPanel = new JPanel(new GridLayout(0,4), true);
		gridPanel.setBackground(Color.white);
		JPanel[] containers = new JPanel[n];
		for (int i=0; i<n; i++) {
			containers[i] = new JPanel(new SpringLayout(), true);
			containers[i].setPreferredSize(new Dimension(100,230));
			containers[i].setBorder(BorderFactory.createTitledBorder("Container "+(i+1)));
			containers[i].setBackground(Color.white);
			gridPanel.add(containers[i]);
		}
		return gridPanel;
	}

	public ContainersGraph() {
		super(new BorderLayout(), true);
		this.setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createEmptyBorder(0,5,0,5),
				BorderFactory.createLoweredBevelBorder()
		));

		cPanel = new JPanel(new BorderLayout(), true);
		cPanel.add(createContainers(nContainers));
		scrollPane = new JScrollPane(cPanel); 
		this.add(scrollPane, BorderLayout.CENTER);
	}
}